package com.airspyar;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.codehaus.jackson.annotate.JsonAnySetter;

public class JSONFlightState{
	private String from, to, airline, aircraft, img, imgBig, author;
	private Pattern pattern;
	private Matcher m;
	
	public JSONFlightState(){
		from=new String();
		to=new String();
		airline=new String();
		aircraft=new String();
		img=new String();
		imgBig=new String();
	}
	
	public void setFrom(String from){
		pattern=Pattern.compile("(.+)\\(\\<a href=(?:.*)");
		m=pattern.matcher(from);
		if(m.matches())
			this.from=m.group(1);
		else
			this.from=from;
	}
	
	public void setTo(String to){
		pattern=Pattern.compile("(.+)\\(\\<a href=(?:.*)");
		m=pattern.matcher(to);
		if(m.matches())
			this.to=m.group(1);
		else
			this.to=to;
	}	
	
	public void setAirline(String airline){
		pattern=Pattern.compile("<a (?:.*)>(.+)<(?:.*)a>");
		m=pattern.matcher(airline);
		if(m.matches())
			this.airline=m.group(1);
		else 
			this.airline=airline;
	}	
	
	public void setAircraft(String aircraft){
		this.aircraft=aircraft;
	}	
	
	public void setImg(String img){
		pattern=Pattern.compile("(?:.*)<span>&copy;\\s(.+)</span>(?:.*)<a href=\\\"(\\S+)\\\"(?:.*)>(?:.*)<img src=\\\"(\\S+)\\\"(?:.*)");
		m=pattern.matcher(img);

		if(m.matches()){
			this.img=m.group(3);
			this.author=m.group(1);
			this.imgBig=m.group(2);
		}
	}	
	
	@JsonAnySetter
	public void handleUnknown(String key, Object value) {}
	
	public String getAuthor(){
		return author;
	}
	
	public String getFrom(){
		return from;
	}
	
	public String getTo(){
		return to;
	}	
	
	public String getAirline(){
		return airline;
	}	
	
	public String getAircraft(){
		return aircraft;
	}	
	
	public String getImg(){
		return img;
	}	
	
	public String getImgBig(){
		return imgBig;
	}	
}